﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace UFrame
{
    public class QueueLock : MonoBehaviour
    {
        public static QueueLock I;

        public Dictionary<string, Queue<QueueState>> queueDic = new Dictionary<string, Queue<QueueState>>();


        public void Awake()
        {
            I = this;
        }


        public void Add(string name, Action action)
        {
            var newState = new QueueState()
            {
                method = action,
            };
            if (queueDic.ContainsKey(name) == false)
            {
                queueDic.Add(name, new Queue<QueueState>());
            }

            queueDic[name].Enqueue(newState);
        }

        public void Next(string name)
        {
            var state = queueDic[name].Dequeue();
            state.method();
        }


        public class QueueState
        {
            public Action method;
        }
    }
}